package com.example.wei.mvp.ui.presenter;

import com.example.wei.mvp.api.Api;
import com.example.wei.mvp.api.RxSchedulers;
import com.example.wei.mvp.base.RxPresenter;
import com.example.wei.mvp.contract.LoginContract;
import com.sina.common.okhttp.bean.HttpResult;

import java.io.File;

import javax.inject.Inject;
import io.reactivex.functions.Consumer;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/5/4.
 */

public class LoginPresenter extends RxPresenter<LoginContract.View> implements LoginContract.Presenter<LoginContract.View> {


    private Api api;

    @Inject
    public LoginPresenter(Api api) {
        this.api = api;
    }




    @Override
    public void postImage(String type,File file) {
        api.psotImage(type,file)
                .compose(RxSchedulers.<HttpResult>io_main())
                .compose(mView.<HttpResult>bindToLife())
                .subscribe(new Consumer<HttpResult>() {
                    @Override
                    public void accept(HttpResult httpResult) throws Exception {
                        if (mView != null) {
                            mView.postImage(httpResult);
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.showError(throwable.getMessage());
                    }
                });
    }
}
